//
//  SDTagsView.m
//  SDEditTagsView
//
//  Created by shansander on 2017/7/27.
//  Copyright © 2017年 shansander. All rights reserved.
//


#import "SDTagsView.h"
#import "SDTagTextField.h"
#import "SDTagViewItem.h"
#import "SDTagBaseControl.h"

@interface SDTagsView ()<UITextFieldDelegate>


@property (nonatomic, weak) UIScrollView * rootScrollView;


/**
 tag的view的list
 */
@property (nonatomic, strong) NSMutableArray * tagViewList;

@property (nonatomic, weak) SDTagTextField * tagTextField;


/**
 编辑的tag的view
 */
@property (nonatomic, weak) SDTagTextField * editTagTextField;



/**
  * 最基础的标签的size
 */
@property (nonatomic, assign) CGSize min_tag_size;


@property (nonatomic, assign) NSInteger currentEditIndex;



@end

@implementation SDTagsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.min_tag_size = CGSizeMake(0, 30);
        self.tagEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);

        //define config data
        self.numberLinesofTags = 0;
        
        self.editable = true;
        
        self.editFont = [UIFont systemFontOfSize:17];
        
        self.tagFont = [UIFont systemFontOfSize:17];
        
        self.tagColor = [UIColor grayColor];
        
        self.tagSelectedColor = [UIColor yellowColor];
        
        self.maxtagstringLength = 10;
        
        self.columnspace = 5.f;
        
        self.rowspace = 5.f;
        
        self.can_delete_tag = YES;
        
        self.currentEditIndex = -1;
        
        [self tagsViewDidLoad];
        
        
        [self sd_configGesture];
        
        
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    NSLog(@"比较谁先执行");

}


- (void)tagsViewDidLoad
{
    
    NSLog(@"执行啥呢");
    [self rootScrollView];
//     判断一下，是不是应该要输入框了
    if (self.editable) {
        [self tagTextField];
     
    }
}

#pragma mark - 初始化tap的事情
- (void)sd_configGesture
{
    UITapGestureRecognizer * simple_gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(on_simple_tap_gesture_action:)];
    
    [self addGestureRecognizer:simple_gesture];
    
}


#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if (textField.tag == 100) {
        if ([string isEqualToString:@"\n"]) {
            
            NSString * tag = textField.text;
            if ([self addTagObject:tag]) {
                
                if (self.tagDelegate && [self.tagDelegate respondsToSelector:@selector(didAddTagString:)]) {
                    [self.tagDelegate didAddTagString:tag];
                }
            }
            textField.text = @"";
        }else{
            [self clearAllTagsSelected];
        }

    }else if (textField.tag == 101){
        if ([string isEqualToString:@"\n"]) {
            
            NSString * tag = textField.text;
            if ([self changeTagObject:tag withIndex:self.currentEditIndex]) {
                if (self.tagDelegate && [self.tagDelegate respondsToSelector:@selector(didChangeTagString:withIndex:)]) {
                    if (self.currentEditIndex >= 0) {
                        [self.tagDelegate didChangeTagString:tag withIndex:self.currentEditIndex];
                    }
                }
            }
            
           
            
           
            textField.text = @"";
        }else{
            [self clearAllTagsSelected];
        }
    }
    
    return true;
}
#pragma mark - UITextField notification
// 废弃了。是textfield的使用的另外一个方式
- (void)textfieldDidChange:(NSNotification *)notification
{
    UITextField * textField = (UITextField *)notification.object;
    
    NSString * toBeString = textField.text;
    
    NSString * lange = [textField.textInputMode primaryLanguage];
    
    if ([lange isEqualToString:@"zh-Hans"]) {
        UITextRange * textRange = textField.markedTextRange;
        //获取高亮部分
        UITextPosition *position = [textField positionFromPosition:textRange.start offset:0];
        if (!position) {
            if (toBeString.length > self.maxtagstringLength) {
                textField.text = [toBeString substringToIndex:self.maxtagstringLength];
            }
        }else{
            
        }
    }else{
        if (toBeString.length > self.maxtagstringLength) {
            textField.text = [toBeString substringToIndex:self.maxtagstringLength];
        }
    }
    
    [self textFielddidChangeCheckoutTextLengthIsOutView];
}
#pragma mark - did change textField
- (void)textField_did_changeText:(UITextField * )textField
{
    NSString * toBeString = textField.text;
    
    NSString * lange = [textField.textInputMode primaryLanguage];
    
    if ([lange isEqualToString:@"zh-Hans"]) {
        UITextRange * textRange = textField.markedTextRange;
        //获取高亮部分
        UITextPosition *position = [textField positionFromPosition:textRange.start offset:0];
        if (!position) {
            if (toBeString.length > self.maxtagstringLength) {
                textField.text = [toBeString substringToIndex:self.maxtagstringLength];
            }
        }else{
            
        }
    }else{
        if (toBeString.length > self.maxtagstringLength) {
            textField.text = [toBeString substringToIndex:self.maxtagstringLength];
        }
    }
    
    [self textFielddidChangeCheckoutTextLengthIsOutView];
}

- (void)canEditTagtextField_did_changeText:(UITextField *)textField
{
    NSString * toBeString = textField.text;
    
    NSString * lange = [textField.textInputMode primaryLanguage];
    
    if ([lange isEqualToString:@"zh-Hans"]) {
        UITextRange * textRange = textField.markedTextRange;
        //获取高亮部分
        UITextPosition *position = [textField positionFromPosition:textRange.start offset:0];
        if (!position) {
            if (toBeString.length > self.maxtagstringLength) {
                textField.text = [toBeString substringToIndex:self.maxtagstringLength];
            }
        }else{
            
        }
    }else{
        if (toBeString.length > self.maxtagstringLength) {
            textField.text = [toBeString substringToIndex:self.maxtagstringLength];
        }
    }
}


#pragma mark -

//TODO: 无耻的全部刷新
- (void)refreshAllTags
{
    
    self.editTagTextField.hidden = YES;
    if (self.numberLinesofTags == 1) {
        
        [self.rootScrollView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (![obj isKindOfClass:[SDTagTextField class]]) {
                [obj removeFromSuperview];
            }
        }];
        
        [self.tagViewList removeAllObjects];
        
        __block CGFloat lastPointX = self.tagEdgeInsets.left;
        
        [self.tagList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {

            NSString * tag_string = obj;
            UIView * unitTagView = nil;
            CGSize tag_size = CGSizeZero;

            if (self.tagDelegate && [self.tagDelegate respondsToSelector:@selector(tagView:withInputTagString:atIndex:)]) {
                unitTagView = [self.tagDelegate tagView:self withInputTagString:tag_string atIndex:idx];
                
                if ([self.tagDelegate respondsToSelector:@selector(tagView:sizeAtIndex:)]) {
                    tag_size = [self.tagDelegate tagView:self sizeAtIndex:idx];
                }
                
            }
            if (!unitTagView) {
                SDTagViewItem * item = [[SDTagViewItem alloc] initWithTag:tag_string];
                item.tagColor = self.tagColor;
                item.tagSelectedColor = self.tagSelectedColor;
                item.tagLabel.font = self.tagFont;
                
                item.selected = false;
                
                tag_size = [item getTagSize];
                unitTagView = item;
            }
            [self.rootScrollView addSubview:unitTagView];
            
            [self.tagViewList addObject:unitTagView];
            NSAssert(tag_size.width != 0, @"不应该 == 0");
            NSAssert(tag_size.height != 0, @"不应该的");
            
            unitTagView.frame = (CGRect){{lastPointX,self.tagEdgeInsets.top},tag_size};
            
            lastPointX += tag_size.width + self.columnspace;
        }];
        
        self.tagTextField.frame = (CGRect){{lastPointX,self.tagTextField.frame.origin.y},{SCREEN_WIDTH / 2.f , self.tagTextField.frame.size.height}};
        
        self.rootScrollView.contentSize = CGSizeMake(lastPointX + SCREEN_WIDTH / 2.f + self.tagEdgeInsets.right, self.rootScrollView.frame.size.height);
        
        if (self.rootScrollView.contentSize.width > self.rootScrollView.frame.size.width) {
            [self.rootScrollView setContentOffset:CGPointMake(self.rootScrollView.contentSize.width - self.rootScrollView.frame.size.width, 0)];
        }
        
    }else if (self.numberLinesofTags == 0){
        [self.rootScrollView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (![obj isKindOfClass:[SDTagTextField class]]) {
                [obj removeFromSuperview];
            }
        }];
        
        [self.tagViewList removeAllObjects];
        
       __block CGPoint lastPoint = CGPointMake(self.tagEdgeInsets.left, self.tagEdgeInsets.top);
        __block CGFloat tag_height = 0;
        [self.tagList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSString * tag_string = obj;
            UIView * unitTagView = nil;
            CGSize tag_size = CGSizeZero;
            
            if (self.tagDelegate && [self.tagDelegate respondsToSelector:@selector(tagView:withInputTagString:atIndex:)]) {
                unitTagView = [self.tagDelegate tagView:self withInputTagString:tag_string atIndex:idx];
                
                if ([self.tagDelegate respondsToSelector:@selector(tagView:sizeAtIndex:)]) {
                    tag_size = [self.tagDelegate tagView:self sizeAtIndex:idx];
                }
                
            }
            if (!unitTagView) {
                SDTagViewItem * item = [[SDTagViewItem alloc] initWithTag:tag_string];
                item.tagColor = self.tagColor;
                item.tagSelectedColor = self.tagSelectedColor;
                item.selected = false;
                item.tagLabel.font = self.tagFont;

                tag_size = [item getTagSize];
                unitTagView = item;
            }
            [self.rootScrollView addSubview:unitTagView];
            
            [self.tagViewList addObject:unitTagView];
            NSAssert(tag_size.width != 0, @"不应该 == 0");
            NSAssert(tag_size.height != 0, @"不应该的");
            tag_height = tag_size.height;
            if ((lastPoint.x + tag_size.width + self.columnspace) > self.bounds.size.width) {
                // 超过界面，跳到下一行
                unitTagView.frame = (CGRect){{self.tagEdgeInsets.left,lastPoint.y +tag_height + self.rowspace},tag_size};

                NSLog(@"执行下一行");
            }else{
                unitTagView.frame = (CGRect){lastPoint,tag_size};
                NSLog(@"执行同一行");
            }
            lastPoint = CGPointMake(CGRectGetMaxX(unitTagView.frame) + self.columnspace, CGRectGetMinY(unitTagView.frame));
            
        }];
        
        self.frame = (CGRect){self.frame.origin,{self.frame.size.width,lastPoint.y + tag_height + self.tagEdgeInsets.bottom}};

        if (lastPoint.x + self.min_tag_size.width > self.bounds.size.width) {
            self.tagTextField.frame = (CGRect){{self.tagEdgeInsets.left,lastPoint.y + tag_height},{self.bounds.size.width - self.tagEdgeInsets.left - self.tagEdgeInsets.right,tag_height}};
            
            self.frame = (CGRect){self.frame.origin,{self.frame.size.width,lastPoint.y + tag_height * 2 + self.tagEdgeInsets.bottom}};
        }else{
            self.tagTextField.frame = (CGRect){{lastPoint.x,lastPoint.y + self.unitTagLineHeight / 2.f - tag_height / 2.f},{self.bounds.size.width - self.tagEdgeInsets.right - lastPoint.x,tag_height}};
        }
        if (self.tagList.count == 0) {
            self.frame = (CGRect){self.frame.origin,{self.frame.size.width,self.min_tag_size.height + self.tagEdgeInsets.top + self.tagEdgeInsets.bottom}};
        }
      
    
        self.rootScrollView.frame = self.bounds;
        
    }
}

#pragma mark - 刷新 点击了一个
- (void)refreshTagViewWithWillEditTagIndex:(NSInteger)index
{
    if (self.currentEditIndex != -1) {
        // 说明已经在编辑的状态了
        
        [self refreshAllTags];
        
        
    }
    SDTagViewItem * will_edit_tag_item = self.tagViewList[index];
    
    self.editTagTextField.frame = (CGRect){will_edit_tag_item.frame.origin, {self.bounds.size.width - will_edit_tag_item.frame.origin.x, self.tagTextField.frame.size.height}};
    
    self.editTagTextField.text = will_edit_tag_item.tag_string;
    
    self.editTagTextField.hidden = NO;
    
    [self.editTagTextField becomeFirstResponder];
    
    
    will_edit_tag_item.hidden = YES;
    CGPoint lastPoint = CGPointMake(CGRectGetMaxX(self.editTagTextField.frame), CGRectGetMinY(self.editTagTextField.frame));
    CGFloat tag_height = self.editTagTextField.frame.size.height;

    for (NSInteger i = index + 1 ; i < self.tagViewList.count; i ++) {
        if (i < self.tagViewList.count) {
            CGSize tag_size = CGSizeZero;
            
            

            SDTagViewItem * unitTagView = self.tagViewList[i];

            if ([self.tagDelegate respondsToSelector:@selector(tagView:sizeAtIndex:)]) {
                tag_size = [self.tagDelegate tagView:self sizeAtIndex:i];
            }
            
            if (tag_size.width == 0) {
                tag_size = [unitTagView getTagSize];
            }
            
            

            tag_height = tag_size.height;
            if ((lastPoint.x + tag_size.width + self.columnspace) > self.bounds.size.width) {
                // 超过界面，跳到下一行
                unitTagView.frame = (CGRect){{self.tagEdgeInsets.left,lastPoint.y +tag_height + self.rowspace},tag_size};
                
                NSLog(@"执行下一行");
            }else{
                unitTagView.frame = (CGRect){lastPoint,tag_size};
                NSLog(@"执行同一行");
            }
            lastPoint = CGPointMake(CGRectGetMaxX(unitTagView.frame) + self.columnspace, CGRectGetMinY(unitTagView.frame));
            
        }
        
    }
    
    self.frame = (CGRect){self.frame.origin,{self.frame.size.width,lastPoint.y + tag_height + self.tagEdgeInsets.bottom}};
    
    if (lastPoint.x + self.min_tag_size.width > self.bounds.size.width) {
        self.tagTextField.frame = (CGRect){{self.tagEdgeInsets.left,lastPoint.y + tag_height},{self.bounds.size.width - self.tagEdgeInsets.left - self.tagEdgeInsets.right, tag_height}};
        
        self.frame = (CGRect){self.frame.origin,{self.frame.size.width,lastPoint.y + tag_height * 2 + self.tagEdgeInsets.bottom}};
    }else{
        self.tagTextField.frame = (CGRect){{lastPoint.x,lastPoint.y + self.unitTagLineHeight / 2.f - self.min_tag_size.height / 2.f},{self.bounds.size.width - self.tagEdgeInsets.right - lastPoint.x,tag_height}};
    }
    if (self.tagList.count == 0) {
        self.frame = (CGRect){self.frame.origin,{self.frame.size.width,self.min_tag_size.height + self.tagEdgeInsets.top + self.tagEdgeInsets.bottom}};
    }
    
    
    self.rootScrollView.frame = self.bounds;
    
    
    self.currentEditIndex = -1;
}

#pragma mark - 清楚所有的tag的选择
- (void)clearAllTagsSelected
{
    [self.tagViewList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj isKindOfClass:[SDTagBaseControl class]]) {
            SDTagBaseControl * control = obj;
            control.selected = false;
        }
    }];
}


- (void)clearAllTags
{
    [self.tagList removeAllObjects];
    
    [self refreshAllTags];
}

- (void)addTags:(NSArray *)tags
{
    [self.tagList addObjectsFromArray:tags];
    
    [self refreshAllTags];
}

- (BOOL)addTagObject:(NSString * )tag
{
    
    if (![tag isEqualToString:@""] && ![self checkoutWiiAllContentisExist:tag]) {
        [self.tagList addObject:tag];
        [self refreshAllTags];
        return YES;
    }
    return NO;
}
- (BOOL)changeTagObject:(NSString * )tag withIndex:(NSInteger)index
{
    if (![tag isEqualToString:@""] && ![self checkoutWiiAllContentisExist:tag]) {
        [self.tagList replaceObjectAtIndex:index withObject:tag];
        [self refreshAllTags];
        return YES;
    }
    return NO;
}

- (void)rmLastTagObject
{
    [self.tagList removeLastObject];
    
    [self refreshAllTags];
}

- (void)rmTagObject:(NSString *)tagString
{


    [self.tagList removeObject:tagString];
    
    
    [self refreshAllTags];
}

- (void)rmTagWithObjectIndex:(NSInteger)tag_index
{
    [self.tagList removeObjectAtIndex:tag_index];
    
    [self refreshAllTags];
}
#pragma mark - 检查，list中存储不存储着tag，
-(BOOL)checkoutWiiAllContentisExist:(NSString *)tag_string
{
   __block NSInteger index = -1;

    [self.tagList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSString * tagStr = obj;
        if ([tagStr isEqualToString:tag_string]) {
            index = idx;
            *stop = YES;
        }
    }];
    
    if (index >= 0) {
        return true;
    }
    
    return false;
    
}
#pragma mark - 检查最后一个tag是不是可以删除ne
- (BOOL)checkoutLastTagCanDeleted
{
    SDTagBaseControl * lastControl = [self.tagViewList lastObject];
    
    return lastControl.selected;
}

#pragma mark - 让最后一个tag呈现出可以删除的状态
- (void)setLastTagViewToDeleted
{
    SDTagBaseControl * lastControl = [self.tagViewList lastObject];
    lastControl.selected = true;
}
#pragma mark - 判断 textField有没有超过边界
- (void)textFielddidChangeCheckoutTextLengthIsOutView
{
    NSString * textString = self.tagTextField.text;
    
    CGFloat text_length = [textString sizeWithAttributes:@{NSFontAttributeName:self.tagTextField.font}].width;
    
    if ((self.tagTextField.frame.size.width + 20) < text_length) {
        
        SDTagBaseControl * view = [self.tagViewList lastObject];
        
        CGPoint lastPoint = CGPointMake(self.tagEdgeInsets.left, CGRectGetMaxY(view.frame) + self.rowspace);
        
        self.tagTextField.frame = (CGRect){lastPoint,{self.bounds.size.width - self.tagEdgeInsets.left - self.tagEdgeInsets.right, self.min_tag_size.height}};
        self.frame = (CGRect){self.frame.origin,{self.frame.size.width, CGRectGetMaxY(self.tagTextField.frame) + self.tagEdgeInsets.bottom}};
        
        self.rootScrollView.frame = self.bounds;

    }
    
    
}

#pragma mark - action gesture

- (void)on_simple_tap_gesture_action:(UITapGestureRecognizer * )gesture
{
    CGPoint touch_point = [gesture locationInView:self];
    NSInteger index = -1;
    
    for (NSInteger i = 0 ; i < self.tagViewList.count; i ++) {
        SDTagViewItem * item = self.tagViewList[i];
        if (CGRectContainsPoint(item.frame, touch_point)) {
            index = i;
        }
    }
    
    
    if (index >= 0) {
//        NSLog(@"我点击了 index = %ld",index);

        [self refreshTagViewWithWillEditTagIndex:index];
        self.currentEditIndex = index;

        
        
    }

    
}

#pragma mark - setter
- (void)setEditable:(BOOL)editable
{
    _editable = editable;
}
- (void)setEditFont:(UIFont *)editFont
{
    _editFont = editFont;
    self.tagTextField.font = editFont;
    
    self.editTagTextField.font = editFont;
    
    NSString * text_string = @"臧";
    if (self.placeholder) {
        text_string = self.placeholder;
    }
    
    
    CGSize size = [text_string sizeWithAttributes:@{NSFontAttributeName:self.tagTextField.font}];
    
    
    self.min_tag_size = CGSizeMake(size.width + 10, MAX(self.min_tag_size.height, size.height + 10));

}

- (void)setPlaceholder:(NSString *)placeholder
{
    _placeholder = placeholder;
    self.tagTextField.placeholder = self.placeholder;
    
    self.editTagTextField.placeholder = self.placeholder;
    
    
    CGSize size = [self.placeholder sizeWithAttributes:@{NSFontAttributeName:self.tagTextField.font}];
    
    self.min_tag_size = CGSizeMake(size.width + 10, MAX(self.min_tag_size.height, size.height + 10));
}

- (void)setMaxtagstringLength:(NSInteger)maxtagstringLength{
    _maxtagstringLength = maxtagstringLength;

    
}

- (void)setNumberLinesofTags:(NSInteger)numberLinesofTags
{
    _numberLinesofTags = numberLinesofTags;
    
    self.unitTagLineHeight = self.frame.size.height - self.tagEdgeInsets.top - self.tagEdgeInsets.bottom;

}

#pragma mark - getter

- (UIScrollView *)rootScrollView
{
    if (!_rootScrollView) {
        UIScrollView * theView = [[UIScrollView alloc] initWithFrame:self.bounds];
        [self addSubview:theView];
        _rootScrollView = theView;
    }
    return _rootScrollView;
}

- (NSMutableArray *)tagList
{
    if (!_tagList) {
        _tagList = [[NSMutableArray alloc] init];
    }
    return _tagList;
}

- (NSMutableArray *)tagViewList
{
    if (!_tagViewList) {
        _tagViewList = [[NSMutableArray alloc] init];
    }
    return _tagViewList;
}
- (SDTagTextField *)tagTextField
{
    if (!_tagTextField) {
        SDTagTextField * theView = [[SDTagTextField alloc] initWithFrame:CGRectMake(self.tagEdgeInsets.left, self.bounds.size.height / 2.f - self.min_tag_size.height / 2.f, self.bounds.size.width - self.tagEdgeInsets.left - self.tagEdgeInsets.right, self.min_tag_size.height)];
        theView.tag = 100;
        [self.rootScrollView addSubview:theView];
        theView.returnKeyType = UIReturnKeyDone;
        // 监听到了删除
        __weak typeof(SDTagsView *) weak_self = self;
        theView.deletedBlock = ^(SDTagTextField *textField) {
            
            if ([weak_self checkoutLastTagCanDeleted]) {
                
                [weak_self rmLastTagObject];
            }else{
                if (weak_self.can_delete_tag) {
                    if (textField.selectedDeleted) {
                        [weak_self setLastTagViewToDeleted];
                    }
                }
            }
            
        };
        
        theView.delegate = self;
        _tagTextField = theView;
        
        [theView addTarget:self action:@selector(textField_did_changeText:) forControlEvents:UIControlEventEditingChanged];
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textfieldDidChange:) name:UITextFieldTextDidChangeNotification object:_tagTextField];
    }
    return _tagTextField;
}

- (SDTagTextField *)editTagTextField
{
    if (!_editTagTextField) {
        SDTagTextField * theView = [[SDTagTextField alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width - self.tagEdgeInsets.left - self.tagEdgeInsets.right, self.tagTextField.frame.size.height)];
        theView.hidden = YES;
        theView.tag = 101;
        theView.delegate = self;
        [theView addTarget:self action:@selector(canEditTagtextField_did_changeText:) forControlEvents:UIControlEventEditingChanged];
        
        [self.rootScrollView addSubview:theView];
        theView.returnKeyType = UIReturnKeyDone;
        
        __weak SDTagsView * weak_self = self;
        theView.deletedBlock = ^(SDTagTextField *textField) {
            NSLog(@"===> delete");
            [weak_self rmTagWithObjectIndex:self.currentEditIndex];
            
            weak_self.currentEditIndex = -1;
        };
        
        _editTagTextField = theView;
    }
    return _editTagTextField;
}


#pragma mark - dealloc

- (void)dealloc
{
    
    NSLog(@"--> dealloc");
//    [[NSNotificationCenter defaultCenter] removeObserver:self];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
